Skip to content

Added typing spec chapter focused on exception behavior - #1718

Merged
erictraut merged 3 commits into
python:mainfrom
erictraut:exceptions_spec
Apr 22, 2024
Merged

erictraut merged 3 commits into
python:mainfrom
erictraut:exceptions_spec

Conversation

@erictraut

Copy link
Copy Markdown
Collaborator

Added typing spec chapter focused on exception behavior — in particular, context managers and whether they suppress exceptions.

…ar, context managers and whether they suppress exceptions.
Comment thread docs/spec/exceptions.rst Resolved
Comment thread docs/spec/exceptions.rst Resolved
@hauntsaninja

Copy link
Copy Markdown
Collaborator

I wonder if it's also worth having one sentence explaining why bool | None does not admit the possibility of exception suppression. E.g. in https://discuss.python.org/t/suppression-of-exceptions-within-context-managers-vs-variable-definitions/47256 I think OP was a little confused till linked to the mypy issue where Jelle proposed this heuristic.

@maxfischer2781

Copy link
Copy Markdown

I wonder if it's also worth having one sentence explaining why bool | None does not admit the possibility of exception suppression.

Yes please. Looking at this without knowing its motivation this is extremely confusing otherwise. Starting from the datamodel, one must assume that -> Literal[True, ...] is the important part no matter what the ... is. So -> bool and -> bool | None would behave the same as they both include the case of True.
Explaining that this rule prefers convenience (only the less common suppressing context managers need special handling) over strictness (the more common non-suppressing context managers need precise annotations) would make it clear that this is not an error but by design.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits.

Comment thread docs/spec/exceptions.rst Resolved
Comment thread docs/spec/exceptions.rst Resolved
@erictraut
erictraut marked this pull request as ready for review April 22, 2024 20:46
@erictraut

Copy link
Copy Markdown
Collaborator Author

The TC has signed off on this change, so I'm proceeding to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants